package com.example.service.Impl;


import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.common.exception.CustomException;
import com.example.mapper.MaterialMapper;
import com.example.pojo.entity.Material;
import com.example.service.IMaterialService;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 物资信息表 服务实现类
 * </p>
 *
 * @author wy
 * @since 2024-07-17
 */
@Service
public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> implements IMaterialService {

    @Autowired
    private MaterialMapper materialMapper;

    @Override
    public void add(Material material) {
        material.setIsDeleted(0);
        material.setVersion(0);
        materialMapper.insert(material);
    }
    /**
     * 删除
     */
    @Override
    public void delete(Integer id) {
        Material material = materialMapper.selectById(id);
        material.setIsDeleted(1);
        updateById(material);
    }

    @Override
    public Page<Material> selectPage(Material material, Integer pageNum, Integer pageSize) {
        MPJLambdaWrapper<Material> mpjLambdaWrapper = new MPJLambdaWrapper<>();
        mpjLambdaWrapper
                .selectAll(Material.class)
                .eq(Material::getIsDeleted,0)
                .eq(ObjectUtil.isNotNull(material.getName()), Material::getName , material.getName());

        return page(new Page<>(pageNum, pageSize), mpjLambdaWrapper);
    }

}
